from django.db import models


class Author(models.Model):
    class Meta:
        verbose_name_plural = "作者"
        verbose_name = "作者"

    SEX = [
        ("1", "male"),
        ("0", "female")
    ]
    id = models.AutoField(primary_key=True)
    name = models.CharField(max_length=20, null=False,verbose_name='姓名')
    sex = models.CharField(choices=SEX, max_length=1,verbose_name='性别')

    def __str__(self):
        return "{}".format(self.name)


# Create your models here.
class Book(models.Model):
    class Meta:
        db_table = "book"
        verbose_name = "书籍"
        verbose_name_plural = "书籍"

    id = models.AutoField(primary_key=True)
    name = models.CharField(max_length=20, null=False, verbose_name="书名")
    price = models.DecimalField(max_digits=6, decimal_places=2, verbose_name="价格")
    isbn_no = models.CharField(max_length=13, verbose_name='isbn编号')
    enterperson = models.CharField(max_length=10, null=True, verbose_name='录入者姓名')
    # introduction = models.TextField(max_length=500, null=True, default="")
    # create_time = models.DateTimeField(auto_created=True)
    # update_time = models.DateTimeField(auto_now=True)
    # author = models.ForeignKey(Author, on_delete=models.CASCADE, default=Author.objects.get_or_create(name="zhangsan",sex="1"))
    author = models.ForeignKey(Author, on_delete=models.CASCADE)

    # author = models.OneToOneField(Author)
    # author = models.ManyToManyField(Author)

    def __str__(self):
        # return "{}:{},{},{}".format(self.id, self.name, self.price, self.isbn_no)
        return "{}".format(self.name)
